home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / binutils.252 / ld / genscrip.dj < prev    next >
Encoding:
Text File  |  1994-12-17  |  7.9 KB  |  237 lines

  1. set -a 
  2. #!/bin/sh
  3. # genscripts.sh - generate the ld-emulation-target specific files
  4. #
  5. # Usage: genscripts.sh srcdir libdir host_alias target_alias \
  6. # default_emulation this_emulation
  7. #
  8. # Sample usage:
  9. # genscripts.sh /djm/ld-devo/devo/ld /usr/local/lib sparc-sun-sunos4.1.3 \
  10. # sparc-sun-sunos4.1.3 sun4 sun3
  11. # produces sun3.x sun3.xbn sun3.xn sun3.xr sun3.xu em_sun3.c
  12.  
  13. export srcdir=$1
  14. export libdir=$2
  15. export host_alias=$3
  16. export target_alias=$4
  17. export DEFAULT_EMULATION=$5
  18. export NATIVE_LIB_DIRS=$6
  19. export EMULATION_NAME=$7
  20.  
  21. # Include the emulation-specific parameters:
  22. . ${srcdir}/emulparams/${EMULATION_NAME}.sh
  23.  
  24. # Set the library search path, for libraries named by -lfoo.
  25. # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
  26. # Otherwise, the default is set here.
  27. #
  28. # The format is the usual list of colon-separated directories.
  29. # To force a logically empty LIB_PATH, do LIBPATH=":".
  30.  
  31. if [ "x${LIB_PATH}" = "x" ] ; then
  32.    if [ "x${host_alias}" = "x${target_alias}" ] ; then
  33.       # Native.
  34.       LIB_PATH=/lib:/usr/lib
  35.       if [ -n "${NATIVE_LIB_DIRS}" ]; then
  36.     LIB_PATH=${LIB_PATH}:${NATIVE_LIB_DIRS}
  37.       fi
  38.       LIB_PATH=${LIB_PATH}:${libdir}
  39.       if [ "${libdir}" != /usr/local/lib ] ; then
  40.         LIB_PATH=${LIB_PATH}:/usr/local/lib
  41.       fi
  42.    else
  43.       # Cross.
  44.       LIB_PATH=
  45.    fi
  46. fi
  47.  
  48. # Always search $(tooldir)/lib, aka /usr/local/TARGET/lib.
  49. export LIB_PATH=${LIB_PATH}:`echo ${libdir} | sed -e s'|/lib$||'`/${target_alias}/lib
  50.  
  51. export LIB_SEARCH_DIRS=`echo ${LIB_PATH} | tr ':' ' ' | sed -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'`
  52.  
  53. # Generate 5 or 6 script files from a master script template in
  54. # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh.  Which one of the 5 or 6
  55. # script files is actually used depends on command line options given
  56. # to ld.  (SCRIPT_NAME was set in the emulparams_file.)
  57. #
  58. # A .x script file is the default script.
  59. # A .xr script is for linking without relocation (-r flag).
  60. # A .xu script is like .xr, but *do* create constructors (-Ur flag).
  61. # A .xn script is for linking with -n flag (mix text and data on same page).
  62. # A .xbn script is for linking with -N flag (mix text and data on same page).
  63. # A .xs script is for generating a shared library with the --shared
  64. #   flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
  65. #   emulation parameters.
  66.  
  67. export SEGMENT_SIZE=${SEGMENT_SIZE-${PAGE_SIZE}}
  68.  
  69. # Determine DATA_ALIGNMENT for the 5 variants, using
  70. # values specified in the emulparams/<emulation>.sh file or default.
  71.  
  72. export DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
  73. export DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
  74. export DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
  75. export DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
  76. export DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
  77.  
  78. export LD_FLAG=r
  79. export DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
  80. export DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
  81. sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | sed -e '/^ *$/d' > \
  82.   ldscripts/${EMULATION_NAME}.xr
  83.  
  84. export LD_FLAG=u
  85. export DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
  86. export CONSTRUCTING=" "
  87. sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | sed -e '/^ *$/d' > \
  88.   ldscripts/${EMULATION_NAME}.xu
  89.  
  90. export LD_FLAG=
  91. export DATA_ALIGNMENT=${DATA_ALIGNMENT_}
  92. export RELOCATING=" "
  93. sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | sed -e '/^ *$/d' > \
  94.   ldscripts/${EMULATION_NAME}.x
  95.  
  96. export LD_FLAG=n
  97. export DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
  98. export TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
  99. sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | sed -e '/^ *$/d' > \
  100.   ldscripts/${EMULATION_NAME}.xn
  101.  
  102. export LD_FLAG=N
  103. export DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
  104. sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | sed -e '/^ *$/d' > \
  105.   ldscripts/${EMULATION_NAME}.xbn
  106.  
  107. if test -n "$GENERATE_SHLIB_SCRIPT"; then
  108.   LD_FLAG=shared
  109.   DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
  110.   CREATE_SHLIB=" "
  111.   # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
  112.   sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | sed -e '/^ *$/d' > \
  113.     ldscripts/${EMULATION_NAME}.xs
  114. fi
  115.  
  116. test "$DEFAULT_EMULATION" = "$EMULATION_NAME" && COMPILE_IN=true
  117.  
  118. # Generate em_${EMULATION_NAME}.c.
  119. # This shell script emits a C file. -*- C -*-
  120. # It does some substitutions.
  121. cat >e${EMULATION_NAME}.c <<EOF
  122. /* This file is is generated by a shell script.  DO NOT EDIT! */
  123.  
  124. /* emulate the original gld for the given ${EMULATION_NAME}
  125.    Copyright (C) 1991, 1993 Free Software Foundation, Inc.
  126.    Written by Steve Chamberlain steve@cygnus.com
  127.  
  128. This file is part of GLD, the Gnu Linker.
  129.  
  130. This program is free software; you can redistribute it and/or modify
  131. it under the terms of the GNU General Public License as published by
  132. the Free Software Foundation; either version 2 of the License, or
  133. (at your option) any later version.
  134.  
  135. This program is distributed in the hope that it will be useful,
  136. but WITHOUT ANY WARRANTY; without even the implied warranty of
  137. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  138. GNU General Public License for more details.
  139.  
  140. You should have received a copy of the GNU General Public License
  141. along with this program; if not, write to the Free Software
  142. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  143.  
  144. #define TARGET_IS_${EMULATION_NAME}
  145.  
  146. #include "bfd.h"
  147. #include "sysdep.h"
  148. #include "bfdlink.h"
  149.  
  150. #include "ld.h"
  151. #include "config.h"
  152. #include "ldmain.h"
  153. #include "ldemul.h"
  154. #include "ldfile.h"
  155. #include "ldmisc.h"
  156.  
  157. static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
  158. static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
  159.  
  160. static void
  161. gld${EMULATION_NAME}_before_parse()
  162. {
  163. #ifndef TARGET_            /* I.e., if not generic.  */
  164.   ldfile_output_architecture = bfd_arch_${ARCH};
  165. #endif /* not TARGET_ */
  166. }
  167.  
  168. static char *
  169. gld${EMULATION_NAME}_get_script(isfile)
  170.      int *isfile;
  171. EOF
  172.  
  173. if test -n "$COMPILE_IN"
  174. then
  175. # Scripts compiled in.
  176.  
  177. # sed commands to quote an ld script as a C string.
  178. sc="-f ${srcdir}/emultempl/stringify.sed"
  179.  
  180. cat >>e${EMULATION_NAME}.c <<EOF
  181. {                 
  182.   *isfile = 0;
  183.  
  184.   if (link_info.relocateable == true && config.build_constructors == true)
  185.     return
  186. EOF
  187. sed $sc ldscripts/${EMULATION_NAME}.xu                     >> e${EMULATION_NAME}.c
  188. echo '  ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
  189. sed $sc ldscripts/${EMULATION_NAME}.xr                     >> e${EMULATION_NAME}.c
  190. echo '  ; else if (!config.text_read_only) return'         >> e${EMULATION_NAME}.c
  191. sed $sc ldscripts/${EMULATION_NAME}.xbn                    >> e${EMULATION_NAME}.c
  192. echo '  ; else if (!config.magic_demand_paged) return'     >> e${EMULATION_NAME}.c
  193. sed $sc ldscripts/${EMULATION_NAME}.xn                     >> e${EMULATION_NAME}.c
  194. echo '  ; else return'                                     >> e${EMULATION_NAME}.c
  195. sed $sc ldscripts/${EMULATION_NAME}.x                      >> e${EMULATION_NAME}.c
  196. echo '; }'                                                 >> e${EMULATION_NAME}.c
  197.  
  198. else
  199. # Scripts read from the filesystem.
  200.  
  201. cat >>e${EMULATION_NAME}.c <<EOF
  202. {                 
  203.   *isfile = 1;
  204.  
  205.   if (link_info.relocateable == true && config.build_constructors == true)
  206.     return "ldscripts/${EMULATION_NAME}.xu";
  207.   else if (link_info.relocateable == true)
  208.     return "ldscripts/${EMULATION_NAME}.xr";
  209.   else if (!config.text_read_only)
  210.     return "ldscripts/${EMULATION_NAME}.xbn";
  211.   else if (!config.magic_demand_paged)
  212.     return "ldscripts/${EMULATION_NAME}.xn";
  213.   else
  214.     return "ldscripts/${EMULATION_NAME}.x";
  215. }
  216. EOF
  217.  
  218. fi
  219.  
  220. cat >>e${EMULATION_NAME}.c <<EOF
  221.  
  222. struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = 
  223. {
  224.   gld${EMULATION_NAME}_before_parse,
  225.   syslib_default,
  226.   hll_default,
  227.   after_parse_default,
  228.   after_allocation_default,
  229.   set_output_arch_default,
  230.   ldemul_default_target,
  231.   before_allocation_default,
  232.   gld${EMULATION_NAME}_get_script,
  233.   "${EMULATION_NAME}",
  234.   "${OUTPUT_FORMAT}"
  235. };
  236. EOF
  237.